package com.gxa.ehome.service.impl;

import com.gxa.ehome.dao.SysUserDao;
import com.gxa.ehome.mapper.SysUserMapper;
import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserService;
import com.gxa.ehome.util.MD5Creater;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service("sysUserService3")

public class SysUserServiceImpl implements SysUserService {

    @Resource
    SysUserMapper sysUserMapper=null;



    SysUserDao sysUserDao=null;

    public SysUserDao getSysUserDao() {
        return sysUserDao;
    }

    public void setSysUserDao(SysUserDao sysUserDao) {
        this.sysUserDao = sysUserDao;
    }
    //为了注入 至少要存在setter





    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,
            rollbackFor={Throwable.class})
    public boolean login() {
        System.out.println("SysUserServiceImpl 的login方法啊");
        return false;
    }

    @Override
    public void deleteById(Integer id) {
        sysUserMapper.delete(id);
    }

    @Override
    public void register(SysUser sysUser) {
    sysUserMapper.save(sysUser);
    }

    @Override
    public void test() {

            //同时调用register和deleteById
            //删除方法
            deleteById(29);


            SysUser sysUser = new SysUser();
            sysUser.setJobNumber("aaa");
            sysUser.setName("bbb");
            sysUser.setPassword(MD5Creater.encode("12345" + sysUser.getPassword()));
           register(sysUser);

    }

    @Override
    @Transactional
    public SysUser selectById(Integer id) {
        SysUser byId = sysUserMapper.findById(id);
        return byId;
    }

    @Override
    public SysUser update(SysUser sysUser) {
        sysUserMapper.upData(sysUser);
        return sysUser;
    }


}
